package game_control;

import org.gamecontrolplus.ControlDevice;
import org.gamecontrolplus.ControlIO;

import processing.core.PApplet;

public class ProcontrollPlugTest extends PApplet{
	
	ControlIO controllIO;
	ControlDevice joypad;
	
	float transX;
	float transY;

	public void setup(){
		size(600,600,OPENGL);
		
		transX = width/2;
		transY = height/2;
		
		controllIO = ControlIO.getInstance(this);
		
		joypad = controllIO.getDevice("Logitech RumblePad 2 USB");
		joypad.plug(this, "handleButton1Press", ControlIO.ON_PRESS, 1);
		joypad.plug(this, "handleButton1Release", ControlIO.ON_RELEASE, 1);
		joypad.plug(this, "handleMovement", ControlIO.WHILE_PRESS, 0);
		
	}
	
	public void handleButton1Press(){
		fill(255,0,0);
		joypad.rumble(1);
	}
	
	public void handleButton1Release(){
		fill(255);
	}
	
	public void handleMovement(final float i_x,final float i_y){
		transX += i_x;
		transY += i_y;
	}
	
	public void draw(){
		background(0);
		lights();
		translate(transX,transY,0);
		box(200);
	}
	
	

	public static void main(String[] args){
		PApplet.main(new String[] {ProcontrollPlugTest.class.getName()});
	}
}

